package com.topnav.mc.config;

import com.topnav.mc.talkback.CallHandler;
import com.topnav.mc.talkback.UserRegistry;
import com.topnav.mc.talkback.helloword.HelloWordHandler;
import org.kurento.client.KurentoClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean;

/**
 * 对讲模块的CONFIG
 */
//@Configuration
//@EnableWebSocket
public class KurentoConfig implements WebSocketConfigurer {
    @Autowired
    private HelloWordHandler helloWordHandler;

/*
    @Bean
    public CallHandler callHandler() {
        return new CallHandler();
    }

    @Bean
    public UserRegistry registry() {
        return new UserRegistry();
    }

*/
    @Bean
    public KurentoClient kurentoClient() {
        return KurentoClient.create();
    }


    @Bean
    public ServletServerContainerFactoryBean createServletServerContainerFactoryBean() {
        ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
        container.setMaxTextMessageBufferSize(32768);
        return container;
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        //registry.addHandler(callHandler(), "/call");
        registry.addHandler(helloWordHandler, "/helloworld")
                .setAllowedOrigins("*");
    }
}
